package com.part2.action.common.form;

import java.util.HashMap;
import java.util.Iterator;

import org.apache.struts.upload.FormFile;


public class FileValueObject implements java.io.Serializable {

	/**
	 * A Hashmap that store info fields(including guid, templateid, info
	 * elements, etc.)
	 * 
	 * @uml.property name="mFields"
	 * @uml.associationEnd multiplicity="(0 1)"
	 *                     qualifier="pName:java.lang.String org.apache.struts.upload.FormFile"
	 */
	private HashMap<String, FormFile> mFields;

	public FileValueObject() {
		mFields = new HashMap<String, FormFile>();
	}

	public FileValueObject(HashMap<String, FormFile> pFields) {
		setFields(pFields);
	}

	/**
	 * 
	 * @uml.property name="mFields"
	 */
	public HashMap<String, FormFile> getFields() {
		return mFields;
	}

	/**
	 * 
	 * @uml.property name="mFields"
	 */
	public void setFields(HashMap<String, FormFile> pFields) {
		mFields = pFields;
	}

	public void addFields(HashMap<String, FormFile> pFields) {
		mFields.putAll(pFields);
	}

	/**
	 * Gets info value object field field name
	 * 
	 * @param pName
	 * @return
	 */
	public FormFile getField(String pName) {
		FormFile fieldValue = mFields.get(pName);
		return fieldValue;
	}

	public void setField(String pName, FormFile pValue) {
		mFields.put(pName, pValue);
	}

	public String toString() {
		StringBuffer ret = new StringBuffer();
		ret.append("\n------------File Value Object----------");
		Iterator keys = mFields.keySet().iterator();
		while (keys.hasNext()) {
			String key = (String) keys.next();
			ret.append("\n" + key + ":" + getField(key).getFileName());
		}
		return ret.toString();
	}
}